package it.polimi.traveldream.ejb.acquistomanagement;

import it.polimi.traveldream.ejb.invito.Invito;
import it.polimi.traveldream.ejb.pacchettomanagement.Pacchetto;
import it.polimi.traveldream.ejb.usermanagement.User;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;

/**
 * Entity implementation class for Entity: PacchettoEntity
 *
 */
@Entity
@Table(name="ACQUISTO")
@NamedQueries({
	@NamedQuery(name=Acquisto.FIND_ALL,
				query="SELECT a FROM Acquisto a "),
	@NamedQuery(name=Acquisto.findAcquisti,
				query="SELECT a FROM Acquisto a WHERE a.utente.username = :username")
})
public class Acquisto implements Serializable {

	public Acquisto() {
		super();
	}

	private static final long serialVersionUID = 1L;
	
	public static final String FIND_ALL = "Acquisto.findAll";
	public static final String findAcquisti = "Acquisto.findAcquisti";
	
	@Id
	@GeneratedValue (strategy=GenerationType.IDENTITY)
	private int idAcquisto;
	
	private int numPosti;
	
	private float prezzo;
	
	@OneToOne(fetch=FetchType.LAZY, mappedBy="acquisto")
	private Invito invito;
	
	@OneToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="IDPACCHETTO")
	private Pacchetto pacchetto;
	
	@ManyToOne
	@JoinTable(name = "AhasUser",
	inverseJoinColumns={@JoinColumn(name="username",referencedColumnName="USERNAME")}, joinColumns={@JoinColumn(name="idAcquisto", referencedColumnName="IDACQUISTO")})
	private User utente;

	public Acquisto(AcquistoDTO nuovo){
        
        this.numPosti		= nuovo.getNumPosti();
        this.prezzo			= nuovo.getPrezzo();
    }
	
	public int getIdAcquisto() {
		return idAcquisto;
	}

	public void setIdAcquisto(int idAcquisto) {
		this.idAcquisto = idAcquisto;
	}

	public int getNumPosti() {
		return numPosti;
	}

	public void setNumPosti(int numPosti) {
		this.numPosti = numPosti;
	}

	public float getPrezzo() {
		return prezzo;
	}

	public void setPrezzo(float prezzo) {
		this.prezzo = prezzo;
	}

	public Pacchetto getPacchetto() {
		return pacchetto;
	}

	public void setPacchetto(Pacchetto pacchetto) {
		this.pacchetto = pacchetto;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public static String getFindAll() {
		return FIND_ALL;
	}

	public Invito getInvito() {
		return invito;
	}

	public void setInvito(Invito invito) {
		this.invito = invito;
	}

	public User getUtente() {
		return utente;
	}

	public void setUtente(User utente) {
		this.utente = utente;
	}
	
	
	
	
}